package com.fesine.jms.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

import javax.annotation.Resource;
import javax.jms.*;

/**
 * @description: 生产者实现类
 * @author: Fesine
 * @createTime:2017/9/3 15:26
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/9/3 15:26
 */
public class ProducerServiceImpl implements ProducerService {

    @Autowired
    private JmsTemplate jmsTemplate;
    //@Resource(name = "queueDestination")
    @Resource(name = "topicDestination")
    private Destination destination;
    @Override
    public void sendMessage(String msg) {
        //使用jms发送消息
        jmsTemplate.send(destination, new MessageCreator() {
            @Override
            public Message createMessage(Session session) throws JMSException {
                //将寡字符串包装成消息返回
                TextMessage message = session.createTextMessage(msg);
                return message;
            }
        });
        System.out.println("发送消息:" + msg);
    }
}
